package com.yunhe.sms.service.system.impl;

import com.yunhe.commens.dto.Pagedao;
import com.yunhe.commens.util.DaoFactory;
import com.yunhe.sms.dao.system.UserDao;
import com.yunhe.sms.entity.system.User;
import com.yunhe.sms.service.system.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author LeiPeifeng
 * @version V1.0
 * @date 2017/10/25 0025 11:46
 * @Description: 实现UserService 接口
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;
    @Override
    public void save(User user) {
        userDao.save ( user );
    }

    @Override
    public void update(User user) {
        userDao.update ( user );
    }

    @Override
    public void updatepwd(String password,String name) {
        userDao.updatepwd ( password,name );
    }

    @Override
    public void deleted(String ids) {
        String[] split = ids.split ( "," );
        for (String id : split){
            userDao.deleted ( new Long(id) );
        }
    }

    @Override
    public List<User> findList() {
        return userDao.findList ();
    }

    @Override
    public User findOne(Long id) {
        return userDao.findOne ( id );
    }

    @Override
    public Pagedao<User> findPage(int offset, int limit) {
        Pagedao<User> pagedao =new Pagedao<> ();
        List<User> findpage=null;
        int count = userDao.count ( );//总数
        if (count>0){
            findpage = userDao.findpage ( offset, limit );//本业数据
            pagedao.setPage ( offset/limit+1 );
            pagedao.setSize ( limit );
        }
        pagedao.setTotal ( count);
        pagedao.setRows ( findpage );
        return pagedao;
    }



    @Override
    public User user(String name) {
        User user = userDao.verifyname ( name );
        return user;
    }
}
